package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.TbSellerService;
import com.sun.org.apache.regexp.internal.RE;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@RequestMapping("/sellerController")
@Controller
public class SellerController {

    private Logger logger = LoggerFactory.getLogger(SellerController.class);

    @DubboReference
    private TbSellerService tbSellerService;
    @RequestMapping("/toShow")
    public String toShow(){
        return "/admin/seller";
    }
    @RequestMapping("/listSeller")
    @ResponseBody
    public Result listSeller(){
        try {
            List<TbSeller> list = tbSellerService.listSeller();
            return Result.OK().setData(list);
        }catch (Exception e){
            logger.error("商家列表查询失败 {}",e);
            return Result.ER();
        }
    }
    @RequestMapping("/selectSellerById")
    @ResponseBody
    public Result selectSellerById(String id){
        String sellerId = id.substring(1, id.length() - 1);
        try {
            TbSeller tbSeller = tbSellerService.selectSellerById(sellerId);
            return Result.OK().setData(tbSeller);
        }catch (Exception e){
            logger.error("商家列表查询失败 {}",e);
            return Result.ER();
        }
    }
    @RequestMapping("/updateStatusById")
    @ResponseBody
    public Result updateStatusById (String sellerId){
        try {
            tbSellerService.updateStatusById(sellerId);
            return Result.OK();
        }catch (Exception e){
            logger.error("商家审核修改失败 {}",e);
            return Result.ER();
        }
    }
}
